package com.smartwebx.ha.web.util.kml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.smartwebx.ha.util.IsoLine;
import com.smartwebx.ha.util.IsoPoint;
import com.smartwebx.ha.util.IsoProperty;

public class GetIsoLine {
	@SuppressWarnings("unchecked")
	public IsoProperty readIsoLine(String str) throws IOException{
		IsoProperty isoProperty= new IsoProperty();
		List<IsoPoint> isopoints= new ArrayList<IsoPoint>();
		List<IsoLine> isoLines= new ArrayList<IsoLine>();
		String str2 = str.replaceAll(":", "|");
		String[] s=str2.split("\\|");
		StringBuffer isoLineStr = new StringBuffer();
		String lineStartPoint,lineEndPoint;
		
		int i,j=0,lineStartPointIndex;
		for(i=j; i<s.length; i++){
			IsoPoint isoPoint = new IsoPoint();
			IsoPoint isoStartPoint = new IsoPoint();
			IsoLine isoLine = new IsoLine();
			lineStartPoint=s[j];//每条线开始点的坐标
			if(s[i].startsWith("dzx")){
				lineEndPoint=s[i-1];//每条线结束的坐标
				String[] s2=s[i].split(",");
				if(!lineStartPoint.equals(lineEndPoint)){
					isoStartPoint.setPoints(lineStartPoint);
					isoStartPoint.setPointVal(s2[1]);
					isopoints.add(isoStartPoint);
				}
				isoPoint.setPoints(s[i-1]);
				isoPoint.setPointVal(s2[1]);
				isopoints.add(isoPoint);
				isoLineStr.delete(isoLineStr.length()-1, isoLineStr.length());
				isoLine.setPoints(isoLineStr.toString());
				isoLines.add(isoLine);
				isoLineStr=new StringBuffer();
				isoProperty.setIsoLines(isoLines);
				isoProperty.setIsoPoints(isopoints);
				j=i+1;
			}else{
				isoLineStr.append(s[i]).append(";");
			}
		}
		return isoProperty;
	}

}
